package com.ruoyi.mobile.project.ums.service;

import com.github.pagehelper.PageHelper;
import com.ruoyi.db.ums.domain.UmsFeedback;
import com.ruoyi.db.ums.domain.query.UmsFeedbackQueryVo;
import com.ruoyi.db.ums.mapper.UmsFeedbackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author Yogeek
 * @date 2018/8/27 11:39
 */
@Service
public class WxUmsFeedbackService
{
    @Autowired
    private UmsFeedbackMapper feedbackMapper;

    /**
     * 添加用户反馈
     *
     * @author 张涛
     * @param feedback
     * @return
     */
    public int add(UmsFeedback feedback)
    {
        feedback.setAddTime(LocalDateTime.now());
        feedback.setUpdateTime(LocalDateTime.now());
        return feedbackMapper.insertUmsFeedback(feedback);
    }

    /**
     * 获取用户反馈列表
     *
     * @author 张涛
     * @param userId
     * @param username
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @return
     */
    public List<UmsFeedback> querySelective(Long userId, String username, Integer page, Integer limit, String sort, String order)
    {
        UmsFeedbackQueryVo umsFeedbackQueryVo = new UmsFeedbackQueryVo();
        if (userId != null) {
            umsFeedbackQueryVo.setUserId(userId);
        }
        if (!StringUtils.isEmpty(username)) {
            umsFeedbackQueryVo.setUsername(username);
        }
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            umsFeedbackQueryVo.setOrder(order);
            umsFeedbackQueryVo.setSort(sort);
        }

        PageHelper.startPage(page, limit);
        return feedbackMapper.selectUmsFeedbackList(umsFeedbackQueryVo);
    }
}
